package cn.com.bluemoon.daps.model.mapper;

import cn.com.bluemoon.daps.model.entity.DapDataModelTablePartition;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 数据模型-模型中设计表-分区表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2020-08-03
 */
@Repository
public interface DapDataModelTablePartitionMapper extends BaseMapper<DapDataModelTablePartition> {

    /**
     * 删除备份索引
     * @param modelId
     */
    @Delete("delete from dap_data_model_table_partition where data_model_id = #{modelId} and p_id != '0'")
    void deletePartition(@Param("modelId") String modelId);

    /**
     * 获得到新增的表分区
     * @param nowTableId
     * @param oldTableId
     * @return
     */
    List<DapDataModelTablePartition> selectInsertPartition(@Param("nowTableId") String nowTableId,
                                                           @Param("oldTableId") String oldTableId);

    /**
     * 获得到删除的表分区
     * @param nowTableId
     * @param oldTableId
     * @return
     */
    List<DapDataModelTablePartition> selectDeletePartition(@Param("nowTableId") String nowTableId,
                                                           @Param("oldTableId") String oldTableId);
    /**
     * 获取模型表分区信息
     *
     * @param modelId 模型id
     * @param newest 最新
     * @return 获取模型表分区信息
     */
    List<DapDataModelTablePartition> findByModelIdAndNewest(@Param("modelId") String modelId, @Param("newest") boolean newest);
}
